package adv7.bank2;


/**
 * @author oldliu
 * @since 1.0
 */
//挣钱的人
public class Depositer extends Thread{
    private final Account ac;

    public Depositer(String name, Account ac){
        super(name);
        this.ac=ac;
    }
    @Override
    public void run() {
        while (true){
            try {
                sleep(5000);
                System.out.println(super.getName()+"准备存钱，当前余额是"+ac.getMoney()+"元");
                ac.deposit(6000);
                System.out.println(super.getName()+"存了6000，当前余额是"+ac.getMoney()+"元");

                synchronized (ac){//发通知要上锁
                    ac.notifyAll();
                }
            } catch (InterruptedException e) {
                 e.printStackTrace();
            }
        }
    }
}
